package com.zt.questionnaire.db.entity;

import com.zt.questionnaire.common.annotation.validator.groups.AddGroup;
import com.zt.questionnaire.common.bean.question.AnswerBean;
import com.zt.questionnaire.common.typehandler.EntityJsonListTypeHandler;
import com.zt.questionnaire.common.typehandler.EntityReportQuestionListTypeHandler;
import lombok.Data;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.annotation.ColumnType;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 报告表(3套问卷基础信息表
 *
 * @author funnywus
 * @email funnywus@163.com
 * @date 2023-09-04 14:27:38
 */
@Data
@Table(name = "report")
public class ReportEntity {

    /**
     * 报告id
     */
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private Long id;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 问卷类型。1: onboarding问卷，2：week1问卷，3：week2问卷
     */
    @NotNull(message = "问卷类型不能为空", groups = AddGroup.class)
    private Integer type;
    /**
     * 问题列表
     **/
    @ColumnType(column = "question_list", jdbcType = JdbcType.VARCHAR, typeHandler = EntityReportQuestionListTypeHandler.class)
    private List<Question> questionList;
    /**
     * 答案列表，一个问题对应多个答案（多选的格式）
     **/
    @ColumnType(column = "answer_list", jdbcType = JdbcType.VARCHAR, typeHandler = EntityJsonListTypeHandler.class)
    private List<List<Answer>> answerList;
    /**
     * 提交时间
     */
    private Long submitTime;

    /**
     * 用户选择的答案id列表,答案集合(多选)，答案的顺序必须和问题的顺序一致
     **/
    @NotEmpty(message = "答案列表不能为空", groups = AddGroup.class)
    @Transient
    private List<List<AnswerBean>> answerLists;

    /**
     * 扩展报告信息
     */
    @Transient
    private Object extend;

    /**
     * 用户头像
     */
    @Transient
    private String avatarUrl;

    @Data
    public static class Question {
        /**
         * 问题类型
         */
        private String type;

        /**
         * 标题
         */
        private String title;
    }

    @Data
    public static class Answer {
        /**
         * 标题,多选题，量表题有
         */
        private String title;

        /**
         * 答案
         */
        private String content;
    }
}
